<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增呼应请求')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-request-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">呼应标题：</label>
            <div class="col-sm-8">
                <input name="hybt" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">呼应内容：</label>
            <div class="col-sm-8">
                <input name="hynr" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8 fileinput fileinput-new" data-provides="fileinput"
                 style="text-align: center; margin-bottom: 0;">
                <span class="btn btn-white btn-file">
                    <span class="fileinput-new">选择图片</span>
                    <input name="photo" type="hidden" value="">
                    <input name="photoList" type="hidden" value="">
                    <input id="williamYe" type="file" multiple="multiple">
                </span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    var prefix = ctx + "control/request";
    $("#form-request-add").validate({
        focusCleanup: true
    });

    $('#williamYe').on('change.bs.fileinput ', function (e) {
        // 处理自己的业务
        if (this.files[0]) {
            // str = ",";
            for (var i = 0; i < this.files.length; i++) {
                const formData = new FormData();
                formData.append('file', this.files[i]);
                $.operate.fileUpload(formData,$('input[name="photo"]'));
                //str += $('input[name="photo"]').val();
            }
            //$('input[name="photo"]').val(str);
        } else {
            $('input[name="photo"]').val("");
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            save(prefix + "/add", $('#form-request-add').serialize(), function (res) {
                if (res.success) {
                    $.modal.close();
                    window.parent.parent.$.modal.openTab("呼应", $.common.setURL("/control/request"));
                }
            });
        }
    }

    function save(url, data, callback) {
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            beforeSend: function (request) {
                request.setRequestHeader("X-Access-Token", storage.get("token"));
            },
            success: function (result) {
                callback(result);
            }
        };
        $.ajax(config)
    }

</script>
</body>
</html>
